package main

import (
	"encoding/xml"
	"os"
	"fmt"
	"io/ioutil"
)

type Recurlyservers struct {
	XMLName     xml.Name `xml:"servers"`
	Version     string `xml:"version,attr"`
	Svs         []server `xml:"server"`
	Description string `xml:",innerxml"`
}

type server struct {
	XMLName    xml.Name `xml:"server"`
	ServerName string `xml:"ServerName"`
	ServerIP   string `xml:"serverIP"`
}

func main() {
	file, err := os.Open("xml/servers.xml")
	if err != nil {
		fmt.Printf("error1: %v", err)
		return
	}

	defer file.Close()

	data, err := ioutil.ReadAll(file)
	if err != nil {
		fmt.Printf("error2: %v", err)
		return
	}

	v := Recurlyservers{}
	err = xml.Unmarshal(data, &v)
	if err != nil {
		fmt.Printf("error3: %v", err)
		return
	}

	fmt.Println(v)

	fmt.Println(v.Description)
	fmt.Println(v.Version)
	fmt.Println(v.XMLName)
	fmt.Println(v.Svs[1].ServerIP)
}